import com.sun.media.sound.SF2Layer;

import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ASUS
 * Date: 2023-04-05
 * Time: 9:58
 */
public class Test {
    public static void main(String[] args) {
        int[] array = new int[]{1,2,3,4};
        sum(array);
        System.out.println(Arrays.toString(array));

    }
    public static void sum(int[] array) {
        int i = 0;
        for (i = 0; i < array.length; i++) {
            i += array[i];
        }
    }
    public static void main21(String[] args) {
    int[] array = new int[]{1,2,3};
    func3(array);
        System.out.println(Arrays.toString(array));
    }
    public static void func3(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = array[i] * 2;
        }
    }
    public static void main20(String[] args) {
        int[] array = new int[100];
        for (int i = 0; i < array.length; i++) {
            array[i] = i + 1;

        }
        System.out.println(Arrays.toString(array));
    }
    public static void main19(String[] args) {
        int[][] array1 = new int[2][];
        array1[0] = new int[3];
        array1[1] = new int[5];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) {
                System.out.print(array1[i][j]+" ");
            }
            System.out.println();
        }
        System.out.println(array1.length);
        System.out.println(array1[1].length);
    }
    public static void main18(String[] args) {
        int[][] array1 = {{1,2,3},{4,5,6}};
        int[][] array2 = new int[2][3];
        int[][] array3 = new int[][]{{1,2,3},{4,5,6}};
        System.out.println(array1.length);
        System.out.println(array1[1].length);

        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) {
                System.out.print(array1[i][j]+" ");
            }
            System.out.println();
        }
        System.out.println("===================");
        for (int[] tmp:array1) {
            for (int x:tmp) {
                System.out.print(x + " ");
            }
            System.out.println();
        }
        System.out.println("================");
        String ret = Arrays.deepToString(array1);
        System.out.println(ret);
    }
    public static void main17(String[] args) {
        int[] array = {1,2,3,4,5};
        reverseArray(array);
        System.out.println(Arrays.toString(array));
    }

    public static void reverseArray(int[] array) {
        int i = 0;
        int j = array.length-1;
        while (i  < j) {
            int tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
            i++;
            j--;
        }
    }
    public static void main16(String[] args) {
        int[] array = {1,2,3,4,5};
        int[] copy = new int[array.length];
        System.arraycopy(array,0,copy,0,array.length);
        System.out.println(Arrays.toString(copy));
        //        int[] ret = Arrays.copyOfRange(array,1,3);
//        System.out.println(Arrays.toString(ret));
        /*int[] ret = copy(array);
        System.out.println(Arrays.toString(ret));
        System.out.println("================");
        int[] ret1 = Arrays.copyOf(array,array.length * 2);
        System.out.println(Arrays.toString(ret1));*/
    }
    public static int[] copy(int[] array) {
        int[] copyArray = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            copyArray[i] = array[i];

        }
        return copyArray;
    }
    public static void main15(String[] args) {
        int[] array = {1,2,3,4,5,16,35};
        bubbleSort(array);
        System.out.println("排序后的数组:"+Arrays.toString(array));
        /*int index = Arrays.binarySearch(array,5);
        System.out.println(index);*/
    }

    public static void bubbleSort(int[] array) {
        boolean flg = false;
        for (int i = 0; i < array.length-1; i++) {
            for (int j = 0; j < array.length-1; j++) {
                if (array[j] > array[j+1]) {
                    int tmp = array[0];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    flg = true;
                }
            }
            if (flg == false) {
                break;
            }
        }
    }
    public static void main14(String[] args) {
        int[] array = {1,2,3,13,11,4,5,6,7};
        Arrays.sort(array);
        System.out.println("排序后的数组:"+Arrays.toString(array));
        int index = findVal(array,11);
        System.out.println(index);
    }

    public static int binarySearch(int[] array, int key) {
        int left = 0;
        int right = array.length - 1;
        while (left < right) {
            int m = (left + right) / 2;
            if (array[m] > key) {
                right = m -1;
            }else if(array[m] < key) {
                left = m + 1;
            }else {
                return m;
            }
        }
        return 1;
    }
    public static int findVal(int[] array, int key) {
        for (int i = 0; i < array.length; i++) {
            if (array[i] == key) {
                return i;
            }
        }
        return  -1;
    }
    public static void main13(String[] args) {
        int[] array = {1,2,3,4,5};
        String ret = myToSring(array);
        System.out.println(ret);
        int[] array3 = null;
        System.out.println(Arrays.toString(array3));
    }

    public static String myToSring(int[] array) {
        if(array == null) {
            return "null";
        }
        String ret = "[";
        for (int i = 0; i < array.length; i++) {
            ret += array[i];
            if (i != array.length-1) {
                ret += ",";
            }
        }
        ret +="]";

        return ret;
    }
    public static void main12(String[] args) {
        int[] array = {1,2,3,4,5};
        int[] ret = func2();
        System.out.println(Arrays.toString(ret));

    }
    public static int[] func2() {
        return new int[]{111,222};
    }
    public static void main11(String[] args) {
        int[] array = {1,2,3,4,5};
        printArray(array);
        //System.out.println(array[0]);
//        System.out.println("前："+Arrays.toString(array));
//        func1(array);
//        System.out.println("后："+Arrays.toString(array));

    }

    public static void func1(int[] array) {
        array = new int[]{9,8,7,6};
    }
    public static void printArray(int[] array) {
        //array[0] = 8;
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+"  ");
        }
    }
    public static void main10(String[] args) {
        int[] array = {1,2,3,4,5};
        int[] array2 = array;
        array2[0] = 99;
        String ret1 = Arrays.toString(array);
        String ret2 = Arrays.toString(array2);
        System.out.println(ret1);
        System.out.println(ret2);

    }
    public static void main9(String[] args) {
        int[] array = {1,2,3,4,5};
        System.out.println(array[0]);
        int[] array2 = null;
        System.out.println(array2[0]);
    }
    public static void main8(String[] args) {
        int[] array = {1,2,3,4,5};
        for (int x:array) {
            System.out.print(x+" ");
        }
        System.out.println(Arrays.toString(array));
    }
    public static void main7(String[] args) {
        int[] array = {1,2,3,4,5};
      /*  System.out.println(array[0]);
        array[0] = 99;
        System.out.println(array[0]);*/
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();
        System.out.println(array.length);
        for (int x:array) {
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.println(Arrays.toString(array));
    }
    public static void main6(String[] args) {
        int[] array = {1,2,3,4,5};
        int[] array2 = new int[]{1,2,3,4,5};
        int[] array3 = new int[5];
        char[] chars = new char[10];
    }
    public static int fib2(int n) {
        if (n == 1) {
            return 0;
        }
        if (n == 2) {
            return 1;
        }
        int f1 = 0;
        int f2 = 1;
        int f3 = 0;
        for (int i = 0; i <= n; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
    public static void main5(String[] args) {
        System.out.println(fib2(1));
    }
    public static int count = 0;
    public static int fib(int n) {
        if (n == 1) {
            return 0;
        }
        if (n == 2) {
            count++;
            return 1;
        }
        return fib(n-1) + fib(n-2);
    }
    public static void main4(String[] args) {
       /* System.out.println(fib(1));
        System.out.println(fib(2));
        System.out.println(fib(3));
        System.out.println(fib(4));
        System.out.println(fib(5));*/
        System.out.println(fib(39));
        System.out.println(count);
    }
    public static int sum2(int n) {
        if (n <= 10) {
            return n;
        }
        return sum2( n/ 10)+ n % 10;
    }
    public static int sum(int num) {
        if (num == 1) {
            return 1;
        }
        return num + sum(num - 1);
    }
    public static void print(int num) {
        if (num <= 9) {
            System.out.println(num);
        }else {
            print(num / 10);
            System.out.println(num % 10);
        }
        /* while (num != 0) {
            System.out.println(num %10);
            num /= 10;
        }*/
    }
    public static void main3(String[] args) {
        int num = 123;
        print(num);
        System.out.println(sum(5));
        System.out.println(sum2(193));
    }
    public static int fac(int n) {
        if (n == 1) {
            return 1;
        }
        int tmp = n * fac(n-1);
        return tmp;
    }
    public static void main2(String[] args) {
        System.out.println(fac(5));
    }
    public static void login() {
        Scanner sc = new Scanner(System.in);
        int coumt = 3;
        while(coumt != 0) {
            System.out.println("请输入你的密码：，你有"+coumt+"次机会");

            String password = sc.nextLine();
            if (password.equals("123456")) {
                System.out.println("密码正确！");
                break;
            }else {
                coumt --;
                System.out.println("密码有误，你还有"+coumt+"次机会！，刚刚输入的密码是"+password);
            }

        }
    }
    public static void main1(String[] args) {
        System.out.println("Day 19");
        login();
    }
}
